package com.qire.manhua.activity;

import android.os.Bundle;

import com.qire.antsbinder.dal.exception.DataAccessException;
import com.qire.antscore.annotation.DalExceptionObserve;
import com.qire.antscore.annotation.RouteMapping;
import com.qire.antsrouter.inject.Autowired;
import com.qire.common.constant.Navigation;
import com.qire.common.constant.Url;
import com.qire.common.inject.EventControllerInjector;
import com.qire.common.inject.ViewModelInjector;
import com.qire.common.support.base.BaseActivity;
import com.qire.common.utils.ThemeUtil;
import com.qire.common.utils.ToastHelper;
import com.qire.manhua.R;
import com.qire.manhua.controller.AccountCancellationGuideController;
import com.qire.manhua.databinding.ActivityAccountCancellationGuideBinding;
import com.qire.manhua.model.viewModel.impl.AccountCancellationGuideViewModel;

import androidx.annotation.Nullable;

@RouteMapping(path = Navigation.Page.AccountCancellationGuidePage)
public class AccountCancellationGuideActivity extends BaseActivity<ActivityAccountCancellationGuideBinding> {

    @Autowired(injector = ViewModelInjector.class)
    AccountCancellationGuideViewModel viewModel;

    @Autowired(injector = EventControllerInjector.class)
    AccountCancellationGuideController controller;

    @Override
    public int layoutRid() {
        return R.layout.activity_account_cancellation_guide;
    }

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        ThemeUtil.changeStatusBarLightOrDark(this, true, false);

        viewModel.onAddition(viewDataBinder());
        controller.onAddition(viewModel);
    }

    @Override
    public void finish() {
        if(viewModel.backPanel()) {
            super.finish();
        }
    }

    @DalExceptionObserve(tags = {Url.v5_mobileAuthInfo, Url.FetchVerificationCode,  Url.CheckVerificationCode,
            Url.CheckBeforeCancellationAccount, Url.CancellationAccount, Url.ArtificialCancellationAccount})
    public void simpleExceptionHandle(DataAccessException e) {
        if(e.tag == Url.FetchVerificationCode) {
            // 请求验证码失败 立刻恢复按钮
            viewModel.resetGetCodeButton();
        }
        ToastHelper.showToast(e.extraMsg);
    }
}
